﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using StockShark.Models;

namespace StockShark.ViewModels
{
    public class InstrumentChartData : ChartData
    {
        public List<Quotation> Quotations { get; set; }
        public Instrument Instrument { get; set; }

        public string GetFlotData()
        {
            string data = "[[";
            int step = (DateTime.Today - StartDate).Days / 200 + 1;
            foreach (var q in Quotations)
            {
                if (q.Timestamp.DayOfYear % step == 0)
                    data += "[" + (q.Timestamp - StartDate).Days + ", " + q.Value.ToString().Replace(',', '.') + "],";
            }
            data += "[" + (DateTime.Today - StartDate).Days + ", " + Instrument.EstimatedPrice.ToString().Replace(',', '.') + "]";
            data += "]]";
            return data;
        }
    }
}